/*
 * @Author: 姚潘涛
 * @Date: 2024-04-08 20:36:39
 * @LastEditors: 姚潘涛
 * @LastEditTime: 2024-04-10 09:28:15
 * @FilePath:
 * /xict_ws/src/xcmg-intelligent-cockpit-three/src/xict_ui/include/xict_ui_driver/utils/baseimgsdk.h
 * @Description:
 *
 * Copyright (c) 2024 by pandaman, All Rights Reserved.
 */
#ifndef BaseImageSdk_H
#define BaseImageSdk_H

#include "sub_sdk_define.h"
#include "xict_proto/sensor/image.pb.h"
#include "xict_ui_common/utils/utils.h"
#include <QObject>
#include <ecal/ecal.h>
#include <ecal/msg/protobuf/subscriber.h>

namespace xict_ui_driver {

    enum ImageType {
        FRONT = 0,
        BACK,
        LEFT,
        RIGHT,
        OVERLOOK,
        FRONTWHEEL,
        FRONTBLADE,
        BACKBLADE,
        BLADEMR
    };

    typedef std::function<void(const char*, const xcmg_proto::OpencvImage&)>
        ImageCallback;
    typedef eCAL::protobuf::CSubscriber<xcmg_proto::OpencvImage> ImageMsgSub;

    class ImageSdk {
    public:
        typedef std::shared_ptr<ImageSdk> Ptr;

        static ImageSdk& GetInstance() {
            static ImageSdk demo;
            return demo;
        }

        ImageSdk()  = default;
        ~ImageSdk() = default;

        DECLARE_SDK_SUB_FUNC(FrontImage, ImageCallback,
                             xcmg_proto::OpencvImage);
        DECLARE_SDK_SUB_FUNC(BackImage, ImageCallback, xcmg_proto::OpencvImage);
        DECLARE_SDK_SUB_FUNC(LeftImage, ImageCallback, xcmg_proto::OpencvImage);
        DECLARE_SDK_SUB_FUNC(RightImage, ImageCallback,
                             xcmg_proto::OpencvImage);
        DECLARE_SDK_SUB_FUNC(OverLookImage, ImageCallback,
                             xcmg_proto::OpencvImage);
        DECLARE_SDK_SUB_FUNC(FrontBladeImage, ImageCallback,
                             xcmg_proto::OpencvImage);   // 铲刀前视
        DECLARE_SDK_SUB_FUNC(BackBladeImage, ImageCallback,
                             xcmg_proto::OpencvImage);   // 铲刀后视
        DECLARE_SDK_SUB_FUNC(FrontWheelImage, ImageCallback,
                             xcmg_proto::OpencvImage);   // 前轮视野
        DECLARE_SDK_SUB_FUNC(BladeMRImage, ImageCallback,
                             xcmg_proto::OpencvImage);   // 铲刀三维动画

        DECLARE_SDK_SUB_FUNC(FrontLineImage, ImageCallback,
                             xcmg_proto::OpencvImage);   // 前视野辅助线
        DECLARE_SDK_SUB_FUNC(BackLineImage, ImageCallback,
                             xcmg_proto::OpencvImage);   // 后视野辅助线

        ImageMsgSub front_image_sub_;
        ImageCallback front_image_callback_;

        ImageMsgSub back_image_sub_;
        ImageCallback back_image_callback_;

        ImageMsgSub left_image_sub_;
        ImageCallback left_image_callback_;

        ImageMsgSub right_image_sub_;
        ImageCallback right_image_callback_;

        ImageMsgSub overlook_image_sub_;
        ImageCallback overlook_image_callback_;

        ImageMsgSub front_blade_image_sub_;
        ImageCallback front_blade_image_callback_;

        ImageMsgSub back_blade_image_sub_;
        ImageCallback back_blade_image_callback_;

        ImageMsgSub front_wheel_image_sub_;
        ImageCallback front_wheel_image_callback_;

        ImageMsgSub blade_mr_image_sub_;
        ImageCallback blade_mr_image_callback_;

        ImageMsgSub back_line_image_sub_;
        ImageCallback front_line_image_callback_;

        ImageMsgSub front_line_image_sub_;
        ImageCallback back_line_image_callback_;

    protected:
        inline bool CheckAndSetCallback(const ImageCallback& cb_in,
                                        ImageCallback& cb_target) {
            if (cb_in == nullptr)
                return false;
            cb_target = cb_in;
            return true;
        }

        static ImageSdk* instance_;
    };

}   // namespace xict_ui_driver

#endif   // BaseImageSdk_H
